const fs = require("fs")
const esprima = require("esprima")
const estraverse = require("estraverse")
const escodegen = require("escodegen")
const iconv = require("iconv-lite")
const es_tool = require("../../tools/es_ast_tool")
const akamai_base = require("../common/akamai_base")
const babel_tool = require('../../tools/babel_ast_tool');
const base_tool =  require('../../tools/base_ast_tools');
const {findFuncForConstReturn, findFuncForConstReturnStep2} = require("../common/akamai_base");



// var base_path = "../BUUTkIyZtB";
var base_path = "../sensor_V3/b1";
var ast = es_tool.get_ast_by_file(base_path+"/src.js");
// var ast = es_tool.get_ast_by_file(base_path+"/cc.js");

// step 1
var repeat_vars = es_tool.find_repeat_vars(ast);
var names = es_tool.get_new_name(ast);
ast = base_tool.renameAllFuncParams(ast, names, repeat_vars);
// ast = base_tool.renameAllFuncName(ast, names, repeat_vars);
ast = base_tool.renameAllVar(ast, names, repeat_vars);
ast = base_tool.renameAllCacheParam(ast, names, repeat_vars);

var g_code = `var g_de_map = new Map();
function MapStr(map) {
    var obj = {};
    for (var [key, value] of map) {
        obj[key] = value;
    }
    var jsonString = JSON.stringify(obj);
    console.log(jsonString);
}
`+escodegen.generate(ast);

es_tool.save_to_file(g_code, base_path+"/1.js");
